<?php
/**
 * Introduction: 分销控制器
 * @author: 杨陈鹏
 * @email: yangchenpeng@cdlinglu.com
 */

namespace WeChat\Controller\Goods;



use Common\Controller\WeChat\SignController;

class DistributionController extends SignController
{
    /**
     * Introduction: 获取我的分销商品列表
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function lists()
    {

        $where = I('param.data',1);

        if(!$where['is_action'])
            $where['is_action'] = 1;

        $where['uid'] = self::$uid;

        $page = I('post.page',1);

        $nums = I('post.nums',20);


        $logic = D('Common/Distribution','Logic');

        outPut($logic::getData($where,$page,$nums));



    }
    /**
     * Introduction: 分享成功修改状态
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function success()
    {

        $where = I('post.data');

        if(!$where['goods_id'])
            outPut(['code' => 300, 'msg' => '缺少商品信息']);

        $where['uid'] = self::$uid;

        $logic          = D('Common/Distribution','Logic');
        $goods_logic    = D('Common/Goods','Logic');

        $result = $logic::$model->where($where)->save(['is_action' => 2]);
        if($result !== false){

            //修改商品分享数量
            $goods_logic::$model->where(['id' => $where['goods_id']])->setInc('share_nums',1);

            outPut(['code' => 200]);

        }

        outPut(['code' => 300, '状态更新失败']);

    }

}